package com.dragon.client.controller.wechat;


import com.dragon.common.util.WechatCheckUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx")
@Api(tags = "微信管理")
public class AuthWechatController {



    @GetMapping("checkConfig")
    @ApiOperation(value = "接入微信验证接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "signature",required = true,type = "string",value = "签名"),
            @ApiImplicitParam(name = "timestamp",required = true,type = "string",value = "时间戳"),
            @ApiImplicitParam(name = "nonce",required = true,type = "string",value = "随机字符串"),
            @ApiImplicitParam(name = "echostr",required = true,type = "string",value = "验证通过返回的字符串"),
    })
    public String verifyUrI(
            @RequestParam String signature,@RequestParam String timestamp,
            @RequestParam String nonce, @RequestParam String echostr
    ){
        Boolean verifyResult = WechatCheckUtil.checkSignature(signature, timestamp, nonce);

        if(verifyResult){
            return echostr;
        }
        return "0";
    }
}
